import java.io.*;

public class SaveObject {
    public static void main(String []args) {
        Person person = new Person("lily","female");
        try {
            FileOutputStream fos = new FileOutputStream("person.data");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(person);
            oos.flush();
            oos.close();
        } catch (IOException e) {
            System.out.println(e.toString());
        }

        try {
            FileInputStream fis = new FileInputStream("person.data");
            ObjectInputStream ois = new ObjectInputStream(fis);
            Person person1 = (Person) ois.readObject();
            ois.close();
            System.out.println("name = " + person1.name + ",sex = " + person1.sex);
        } catch (IOException e) {
            System.out.println(e.toString());
        } catch (ClassNotFoundException e) {
            System.out.println(e.toString());
        }
    }
}
